/*
 *  @product.title@
 *  Copyright (C) @product.copyright-year@
 *    @product.vendor@
 *    Registration Number: @product.registration-number@
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package jp.go.aist.six.test.util.orm.inheritance;

import jp.go.aist.six.util.castor.CastorDao;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;



/**
 * @author  Akihito Nakamura, AIST
 * @version $Id: ContainerDao.java 222 2010-12-08 04:09:11Z nakamura5akihito $
 */
public class ContainerDao
    extends CastorDao<String, ContainerX>
{

    /**
     * Constructor.
     */
    public ContainerDao()
    {
        super( ContainerX.class );
    }



    //**************************************************************
    //  Dao, CastorDao
    //**************************************************************

    @Override
    public String create(
                    final ContainerX container
                    )
    {
        if (container.getPersistentID() == null) {
            String  uuid = UUID.randomUUID().toString();
            container.setPersistentID( uuid );
        }

        List<AbstractA>  elements = new ArrayList<AbstractA>();
        for (AbstractA  element : container) {
            element.setMasterObject( container );
            elements.add( element );
        }

        List<AbstractA>  p_elements =
            getForwardingDao( AbstractA.class ).syncAll( elements );
        container.setElement( p_elements );

        return super.create( container );
    }

}
// ContainerDao
